home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / mildred / lha / scrolldemo.lha / ScrollDemo.ascii < prev    next >
Text File  |  1999-01-26  |  12KB  |  363 lines

  1. WBStartup
  2.  
  3. DEFTYPE.w
  4. MCPU Processor
  5. Mc2pCPUmode Processor
  6.  
  7. *ScrVP._ViewPort=0
  8. IsAGA.b=False
  9. Dim PlanarBuf.l(2) ; Base address of planar memory to output c2p to (allowed up to triple buffers)
  10.  
  11. PrefDisplayID.l=$0 ; Default ModeID
  12. PrefDisplayWidth.w=320 ; Default Width
  13. PrefDisplayHeight.w=240 ; Default Height
  14. PrefDisplayBuffering.b=3 ; 1..3. 1=Singlebuffered, 2=Doublebuffered, 3=Triplebuffered
  15.  
  16. SMRMinX=320 ; Minimum width
  17. SMRMinY=240 ; Minimum height
  18. SMRMaxX=640 ; Maximum width
  19. SMRMaxY=480 ; Maximum height
  20.  
  21. #DTAG_DISP=$80000000
  22. #DTAG_DIMS=$80001000
  23. #DTAG_MNTR=$80002000
  24. #DTAG_NAME=$80003000
  25.  
  26. NEWTYPE.SMode
  27.   DID.l
  28.   DWidth.l
  29.   DHeight.l
  30.   DDepth.w
  31.   DType.w
  32. End NEWTYPE
  33.  
  34. DEFTYPE.Hook myhook ; The hook for ASL tag as &myhook
  35. myhook\h_Entry=?hook
  36. MOVE.l a5,globalbase
  37. funcret.l=0
  38.  
  39. Dim SMRtags.TagItem(17)
  40. SMRtags(0)\ti_Tag=#ASLSM_InitialLeftEdge,160 ; X coord of requester
  41. SMRtags(1)\ti_Tag=#ASLSM_InitialTopEdge,0 ; Y coord of requester
  42. SMRtags(2)\ti_Tag=#ASLSM_InitialWidth,300 ; Width of requester
  43. SMRtags(3)\ti_Tag=#ASLSM_InitialHeight,400 ; Height of requester
  44. SMRtags(4)\ti_Tag=#ASLSM_InitialDisplayID,$21000 ; Default ModeID (Pal:LowRes)
  45. SMRtags(5)\ti_Tag=#ASLSM_InitialDisplayDepth,8 ; Default depth (8-bit usually)
  46. SMRtags(6)\ti_Tag=#ASLSM_InitialDisplayWidth,PrefDisplayWidth
  47. SMRtags(7)\ti_Tag=#ASLSM_InitialDisplayHeight,PrefDisplayHeight
  48. SMRtags(8)\ti_Tag=#ASLSM_InitialOverscanType,1 ; Default overscan type (Text)
  49. SMRtags(9)\ti_Tag=#ASLSM_InitialInfoOpened,1 ; Info window?
  50. SMRtags(10)\ti_Tag=#ASLSM_InitialInfoLeftEdge,350 ; X coord of info window
  51. SMRtags(11)\ti_Tag=#ASLSM_InitialInfoTopEdge,50 ; Y coord of info window
  52. SMRtags(12)\ti_Tag=#ASLSM_DoDepth,0 ; Depth gadget? (Generally NO for chunky 8-bit)
  53. SMRtags(13)\ti_Tag=#ASLSM_DoOverscanType,1 ; Overscan gadget?
  54. SMRtags(14)\ti_Tag=#ASLSM_DoWidth,1 ; Width gadget?
  55. SMRtags(15)\ti_Tag=#ASLSM_DoHeight,1 ; Height gadget?
  56. SMRtags(16)\ti_Tag=#ASLSM_FilterFunc,&myhook ; Address of callback hook routine
  57. SMRtags(17)\ti_Tag=#TAG_DONE,0
  58.  
  59. *sreq.SMode=0
  60. *sreq=AllocAslRequest_(2,&SMRtags(0)\ti_Tag)
  61. ok.b=AslRequest_(*sreq,&SMRtags(0)\ti_Tag)
  62.  
  63. If ok<>0
  64.   PrefDisplayID.l=*sreq\DID
  65.   PrefDisplayWidth.w=*sreq\DWidth
  66.   PrefDisplayHeight.w=*sreq\DHeight
  67. EndIf
  68. If (*sreq) Then FreeAslRequest_(*sreq)
  69.  
  70. Goto PrefsSkip
  71.  
  72. ;*************************************************************************
  73. ; This is the statement that the hook will call.  Put the label before
  74. ; the statement you want to jump to.
  75. Runerrsoff
  76. .hook_jump:
  77. Statement hook{*dahook.Hook, modeID.l, *smr.ScreenModeRequester}
  78.   ; We're inside the hook, and supposedly we should be able to do whatever
  79.   ; we want.
  80.   ; Filter modeID's here
  81.   SHARED funcret.l,SMRMinX,SMRMinY,SMRMaxX,SMRMaxY
  82.   DEFTYPE.DisplayInfo DisInfoBuf
  83.   DEFTYPE.DimensionInfo DimInfoBuf
  84.   DEFTYPE.MonitorInfo MonInfoBuf
  85.   DEFTYPE.NameInfo NamInfoBuf
  86.   ;Refer to Includes/Graphics/DisplayInfo.h or view newtypes
  87.   IDhandle.l=FindDisplayInfo_(modeID)
  88.   GetDisplayInfoData_ IDhandle,&DisInfoBuf,SizeOf.DisplayInfo,#DTAG_DISP,0
  89.   GetDisplayInfoData_ IDhandle,&DimInfoBuf,SizeOf.DimensionInfo,#DTAG_DIMS,0
  90.   GetDisplayInfoData_ IDhandle,&MonInfoBuf,SizeOf.MonitorInfo,#DTAG_MNTR,0
  91.   GetDisplayInfoData_ IDhandle,&NamInfoBuf,SizeOf.NameInfo,#DTAG_NAME,0
  92.   ;Do tests. True=Mode is valid, False=mode is invalid.
  93.   ;See newtypes for DisplayInfo,DimensionInfo,MonitorInfo and NameInfo for things to further test
  94.   If DimInfoBuf\MaxDepth<>8
  95.     ;No true-colour modes, only 8-bit
  96.     funcret=False
  97.   Else
  98.     funcret=True
  99.   EndIf
  100. End Statement
  101.  
  102. ;**********************
  103. ; Hook
  104. Macro goto_hook
  105.   JSR `1+6
  106. End Macro
  107.  
  108. globalbase: Dc.l 0
  109.  
  110. hook: ;This hook is called by the filter hook callback from screenmode requester, per item
  111. ; Store registers
  112. MOVEM.l   d1-d7/a0-a6,-(a7) ; Not d0!
  113.  
  114. ; Put parameters into dregs ready for a statement
  115. MOVE.l    a0,d0
  116. MOVE.l    a1,d1
  117. MOVE.l    a2,d2
  118.  
  119. ; Get global variable base
  120. MOVE.l    globalbase,a5
  121.  
  122. ; Goto hook statement
  123. !goto_hook{hook_jump}
  124.  
  125. GetReg d0,funcret ; return accept/discard
  126.  
  127. ; Restore registers
  128. MOVEM.l   (a7)+,d1-d7/a0-a6 ; Not d0!
  129.  
  130. RTS
  131. ;**********************
  132.  
  133. Runerrson
  134. PrefsSkip
  135.  
  136. Function.b InitDisplay{Title$}
  137. ;Creates a display for AGA or Graphics-Card output
  138. ;Title$=The screen title (not displayed)
  139.   SHARED PrefDisplayWidth.w,PrefDisplayHeight.w,PrefDisplayBuffering.b
  140.   SHARED *ScrVP._ViewPort,PrefDisplayID.l,IsAGA.b,PlanarBuf()
  141.   ;Open a test screen first to a) test for AGA or GFX-Card, and b) because the dimensions might be
  142.   ;too large to open a chipram screen, and the dimensions for AGA have not yet been reduced to within limits
  143.   Dim ScrTags.TagItem(13)
  144.   Rect.Rectangle\MinX=0,0,320,240 ; For test
  145.   ScrTags(0)\ti_Tag=#SA_Width,320 ; For test
  146.   ScrTags(1)\ti_Tag=#SA_Height,240; For test
  147.   ScrTags(2)\ti_Tag=#SA_Depth,8
  148.   ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  149.   ScrTags(4)\ti_Tag=#SA_Type,$F
  150.   ScrTags(5)\ti_Tag=#SA_Quiet,True
  151.   ScrTags(6)\ti_Tag=#SA_ShowTitle,False
  152.   ScrTags(7)\ti_Tag=#SA_Behind,True
  153.   ScrTags(8)\ti_Tag=#SA_DClip,&Rect ; For test
  154.   ScrTags(9)\ti_Tag=#SA_Exclusive,False
  155.   ScrTags(10)\ti_Tag=#SA_Draggable,True
  156.   ScrTags(11)\ti_Tag=#SA_AutoScroll,False
  157.   ScrTags(12)\ti_Tag=#TAG_DONE,0
  158.   ScrTags(13)\ti_Tag=#TAG_DONE,0
  159.   UsedChip.l=((320 LSR 3)*240)*8 ; With test params (depth 8)
  160.   FreeChip.l=AvailMem_(#MEMF_CHIP)
  161.   Forbid_
  162.   If ScreenTags(0,Title$,&ScrTags(0))<>0 ; Test for GFX-Card or AGA
  163.     NowChip.l=AvailMem_(#MEMF_CHIP)
  164.     Permit_
  165.     If FreeChip-NowChip<UsedChip
  166.       ; Graphics card screen
  167.       IsAGA=False
  168.       PrefDisplayWidth AND $FFF0 ; For gfx-cards, width to nearest 16
  169.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  170.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  171.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight*PrefDisplayBuffering
  172.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  173.       VWait 5 ; seems to be necessary (safer)
  174.       Free Screen 0
  175.       VWait 5
  176.       If ScreenTags(0,Title$,&ScrTags(0))<>0
  177.         For Loop.w=0 To PrefDisplayBuffering-1
  178.           If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  179. If Window(Loop,0,PrefDisplayHeight*Loop,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  180.           Menus Off
  181.           ScreensBitMap 0,Loop
  182.           *TmpBmp.bitmap=Addr BitMap(Loop)
  183.           Offset.l=*TmpBmp\_ebwidth*(PrefDisplayHeight*Loop)
  184.           For DLoop.w=0 To 8-1 ; Depth of 8
  185.             *TmpBmp\_data[DLoop]=*TmpBmp\_data[DLoop]+Offset
  186.           Next DLoop
  187.         Next Loop
  188.       Else
  189.         Function Return False
  190.       EndIf
  191.     Else
  192.       ; AGA screen
  193.       IsAGA=True
  194.       PrefDisplayWidth AND $FFC0 ; For AGA, width to nearest 64
  195.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  196.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  197.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight ; Seperate buffers
  198.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  199.       ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  200.       Forbid_
  201.       VWait 5 ; seems to be necessary (safer)
  202.       Free Screen 0
  203.       VWait 5
  204.       For Loop.w=0 To PrefDisplayBuffering-1
  205.         If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  206.         If AvailMem_(#MEMF_CHIP)>=(PrefDisplayWidth*PrefDisplayHeight)+16
  207.           Memory.l=AllocMem((PrefDisplayWidth*PrefDisplayHeight)+16,$10002) ; Chip bitmap
  208.           Memory=(Memory+16) AND $FFFFFFF0 ; Align for move16's
  209.           If Memory<>0
  210.             CludgeBitMap Loop,PrefDisplayWidth,PrefDisplayHeight,8,Memory ; Depth 8
  211.             If Loop=0
  212.               ScrTags(12)\ti_Tag=#SA_BitMap,Addr BitMap(0)
  213.               If ScreenTags(0,Title$,&ScrTags(0))=0
  214.                 Permit_
  215.                 Function Return False
  216.               EndIf
  217.             EndIf
  218. If Window(Loop,0,0,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  219.             Menus Off
  220.           Else
  221.             Permit_
  222.             Function Return False
  223.           EndIf
  224.         Else
  225.           Permit_
  226.           Function Return False
  227.         EndIf
  228.         PlanarBuf(Loop)=Memory
  229.       Next Loop
  230.       Permit_
  231.     EndIf
  232.     DEFTYPE.DimensionInfo DimInfoBuf
  233.     GetDisplayInfoData_ FindDisplayInfo_(PrefDisplayID) AND $FFFFFFFF,&DimInfoBuf,SizeOf.DimensionInfo,#DTAG_DIMS,0
  234.     PrefDisplayLeft.w=((DimInfoBuf\TxtOScan\MaxX)-PrefDisplayWidth)/2
  235.     PrefDisplayTop.w=((DimInfoBuf\TxtOScan\MaxY)-PrefDisplayHeight)/2
  236.     *Scr._Screen=Peek.l(Addr Screen(0))
  237.     *ScrVP=ViewPort(0)
  238.     *ScrVP\DxOffset=PrefDisplayLeft,PrefDisplayTop
  239.     ScrollVPort_ *ScrVP
  240.     RethinkDisplay_
  241.     Menus Off
  242.     If *ScrVP\DHeight<>PrefDisplayHeight
  243.       Forbid_
  244.       *Scr\Height=PrefDisplayHeight ; Enforce y clipping
  245.       Permit_
  246.     EndIf
  247.     ScreenToFront_ *Scr
  248.     Function Return True
  249.   Else
  250.     Permit_
  251.     Function Return False
  252.   EndIf
  253. End Function
  254.  
  255. .Main
  256. InitBank 0,PrefDisplayWidth*PrefDisplayHeight,$10000
  257. CludgeBitMap 0,PrefDisplayWidth,PrefDisplayHeight,8,Bank(0)
  258. InitPalette 0,256
  259. LoadBitMap 0,"Stencil.IFF"
  260. If MBitmap(0,PrefDisplayWidth,PrefDisplayHeight)=0 Then Goto Finish
  261. MPlanar16ToBitmap 0,Bank(0)
  262. MMakeStencil 0
  263. LoadBitMap 0,"Image.IFF",0
  264. MPlanar16ToBitmap 0,Bank(0)
  265. If InitDisplay{"Game"}=False Then Goto Finish
  266. ShowPalette 0
  267. *RP._RastPort=RastPort(0)
  268. Mc2pWindow 0,PrefDisplayWidth,PrefDisplayHeight ; Need this line in some form or other
  269. MCludgeBitmap 4,PrefDisplayWidth,PrefDisplayHeight*PrefDisplayBuffering,*RP\_BitMap\Planes-16
  270. If MBitmap(1,PrefDisplayWidth,PrefDisplayHeight)=0 Then Goto Finish
  271. MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
  272. MUseBitmap 0
  273. If MShape(0,64,64)=0 Then Goto Finish
  274. MTable 0,256*256
  275. If ReadFile(0,"Merge50.Table")=0 Then Goto Finish
  276. ReadMem 0,MTablePtr,256*256
  277. CloseFile 0
  278. MTable 1,256*256
  279. If ReadFile(0,"Subtract&Tint.Table")=0 Then Goto Finish
  280. ReadMem 0,MTablePtr,256*256
  281. CloseFile 0
  282.  
  283. .Loop
  284. buf.b=0
  285. its.l=0
  286. cnt.b=0
  287. ResetTimer
  288. While Joyb(0)=0 AND Joyb(1)=0
  289.  
  290.   xpos=Min(SMouseX,PrefDisplayWidth-65)
  291.   ypos=Min(SMouseY,PrefDisplayHeight-65)
  292.   MBlockScroll xpos,ypos,64,64,64,0,1
  293.   MScroll xpos,ypos,64,64,0,0,1
  294.   MUseTable 0
  295.   MMaskScrollMode MReMapMode
  296.   MMaskScroll xpos,ypos,64,64,128,0,1
  297.   MUseTable 1
  298.   MScroll 192,0,64,64,192,0,1
  299.   MMaskScroll xpos,ypos,64,64,192,0,0
  300.   MMaskScrollMode MColourMode
  301.   MScroll 256,0,64,64,256,0,1
  302.   MInk its
  303.   MMaskScroll xpos,ypos,64,64,256,0,0
  304.   MScrollBitmapToShape xpos,ypos,64,64,0,0,1
  305.   MShapeXFlip 0
  306.   MShapeYFlip 0
  307.   MSScrollCut On
  308.   MSScrollShapeToBitmap 0,0,64,64,128,64,0
  309.   MUseTable 0
  310.   MMaskScrollMode MReMapMode
  311.   MScroll 64,64,64,64,64,64,1
  312.   MMaskScroll xpos,ypos,64,64,64,64,0
  313.   MScroll xpos,ypos,64,64,192,64,0
  314.   MScroll 0,63,64,64,0,64,0
  315.   MScroll 1,64,64,64,0,64,0
  316.   MBlockScrollBitmapToShape 64,64,64,64,0,0,0
  317.   MShapeYFlip 0
  318.   MBlockScrollShapeToBitmap 0,0,64,64,256,64,0
  319.  
  320.   ;Display
  321.   If IsAGA
  322.     Mc2p MBitmapPtr(0),PlanarBuf(buf)
  323.     ShowBitMap buf
  324.     If PrefDisplayBuffering>1
  325.       buf+1
  326.       If buf=PrefDisplayBuffering Then buf=0
  327.     EndIf
  328.   Else
  329.     MUseBitmap 4
  330.     If PrefDisplayBuffering>1
  331.       MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,PrefDisplayHeight+(cnt*PrefDisplayHeight),0
  332.     Else
  333.       MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
  334.     EndIf
  335.     MUseBitmap 0
  336.     *RP0._RastPort=RastPort(0)
  337.     *RP1._RastPort=RastPort(Min(PrefDisplayBuffering-1,1+cnt))
  338.     ClipBlit_ *RP1,0,0,*RP0,0,0,PrefDisplayWidth,PrefDisplayHeight,$C0
  339.     If PrefDisplayBuffering=3 Then cnt=1-cnt ; Toggle output buffer
  340.   EndIf
  341.  
  342.   its+1
  343. Wend
  344.  
  345. ;Report
  346. t=Timer
  347. t=Max(t,1)
  348. its=Max(its,1)
  349. a.q=50.0/(t/its)
  350. WBenchToFront_
  351. FindScreen 1
  352. Window 2,16,16,300,40,0,"Test results",1,0
  353. WindowOutput 2
  354. NPrint a," frames per second"
  355. NPrint " "
  356. NPrint "Press mouse/joy button..."
  357. Repeat
  358. Until Joyb(0)<>0 OR Joyb(1)<>0
  359.  
  360. Finish:
  361. End
  362.  
  363.